﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using MVVM_CAD.Algorithms;
using MVVM_CAD.Common;
using MVVM_CAD.Model;

namespace MVVM_CAD.Strategy
{ 
    public class LineToolStrategy : StrategyBase
    {
        public LineToolStrategy(IFigure figure) : base(figure)
        {}

        public override IFigure PerformMouseLeftClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            ClickCount++;
            if (ClickCount == 2)
            {
                //var lineRepresentation = LineRepresentation.GetLineRepresentation(Figure.InitialPoint, point, false);
                //AddPointsToCollection(lineRepresentation);
                return CloseFigureDrawing();
            }
            ValidateFigureIsNew<Line>();
            Figure.PointsCollection.Add(point);
            AddNewObject((DrawingCanvas) canvas, (FigureBase) Figure);
            return Figure;
        }

        public override IFigure PerformMouseLeftClicUpEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseRightClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            ValidateFigureIsNew<Line>();
            return Figure;
        }

        public override IFigure PerformMouseMoveEvent(IPoint point, IEnumerable<IFigure> figures)
        {
            var lineRepresentation = LineRepresentation.GetLineRepresentation(Figure.InitialPoint, point, false);
            lineRepresentation.ForEach(p => Figure.PointsCollection.Add(p));
            ((FigureBase) Figure).MoveHandleTo(point, 2);
            return Figure;
        }

        public override IFigure PerformMouseMoveEvent(DrawingCanvas canvas, CustomPoint point)
        {
            canvas[canvas.VisualCollection.Count - 1].MoveHandleTo(point, 2);
            return Figure;
        }
    }
}
